﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ShoppingCart
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

   <link rel="stylesheet" href="/Content/css/member.css" />
   <style type="text/css">
     .td-goodsname { width:300px; text-align:left;}
      .td-goodsname a{ text-align:left;}
   </style>

    <script type="text/javascript">
        function send_request( url, poststr ) {
            http_request = false;
            if ( window.XMLHttpRequest ) {
                http_request = new XMLHttpRequest();
                if ( http_request.overrideMimeType ) {
                    http_request.overrideMimeType( 'text/xml' );
                }
            } else if ( window.ActiveXObject ) {
                try {
                    http_request = new ActiveXObject( "Msxml2.XMLHTTP" );
                } catch ( e ) {
                    try {
                        http_request = new ActiveXObject( "Microsoft.XMLHTTP" );
                    } catch ( e ) { }
                }
            }
            if ( !http_request ) return false;
            http_request.onreadystatechange = processRequest;
            http_request.open( "POST", url, true );
            http_request.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
            http_request.send( poststr );
        }
        function processRequest() {
            if ( http_request.readyState == 4 ) {
                if ( http_request.status == 200 ) {
                    if ( http_request.responseText == "" )
                        art.dialog.tips( "很抱歉，商品数量修改失败！", 1.5 );
                    else {
                        var returnValue = http_request.responseText.split( "〇" );
                        if ( returnValue[0] == "1" )
                            art.dialog.tips( "很抱歉，商品数量修改失败,商品库存不足！", 1.5 );
                        $( "#tbShoppingCart" ).html( returnValue[1] );
                        $( "#pTotal" ).html( returnValue[2] );
                    }
                } else { art.dialog.tips( "很抱歉，商品数量修改失败！", 1.5 ); }
            }
        }

        function amountJia( obj ) {

            poststr = "cid=" + obj + "&amount=" + ( parseInt( $( "#amount" + obj ).val() ) + 1 );
            send_request( "shoppingCartHandler.ashx", poststr, function () {
                if ( http_request.readyState == 4 && http_request.status == 200 ) {
                    changeShoppingCart( http_request.responseText );
                }
            } );
        }
        function amountJian( obj ) {
            if ( parseInt( $( "#amount" + obj ).val() ) > 1 ) {
                poststr = "cid=" + obj + "&amount=" + ( parseInt( $( "#amount" + obj ).val() ) - 1 );
                send_request( "shoppingCartHandler.ashx", poststr, function () {
                    if ( http_request.readyState == 4 && http_request.status == 200 ) {
                        changeShoppingCart( http_request.responseText );
                    }
                } );
            }
        }


        function changeAmount( obj ) {
            if ( parseInt( $( "#amount" + obj ).val() ) == 0 ) {
                art.dialog.tips( "购买数量不能为0！", 5 );
                return false;
            }
            poststr = "cid=" + obj + "&amount=" + $( "#amount" + obj ).val();
            send_request( "shoppingCartHandler.ashx", poststr, function () {
                if ( http_request.readyState == 4 && http_request.status == 200 ) {
                    changeShoppingCart( http_request.responseText );
                }
            } );
        }

        $( function () {
            $( "#imgSettlement" ).click( function () {
                $.ajax( {
                    type: "POST",
                    url: "detectionSessionHandler.ashx",
                    success: function ( msg ) {
                        if ( msg == "0" )
                            TB_show( null, "login.html?TB_iframe=true&height=370&width=640", false );
                        else if ( msg == "1" )
                            art.dialog.tips( "购物车目前没有加入任何商品！", 1.5 );
                        else if ( msg == "2" )
                            window.location = "order_info.html";
                    }
                } );
                return false;
            } );
        } );



        function setShoppingBody() {

            $.post( "/Service/ShoppingHandler.ashx?type=ShoppingCart", function ( data ) {
                $( '#tbShoppingCart' ).html( data );

            } );
            $.post( "/Service/ShoppingHandler.ashx?type=ShoppingCartTotal", function ( data ) {
                $( '#ShoppingCartTotalBind' ).html( data );

            } );
 
        }

        $( document ).ready( function () {
            setShoppingBody();
        } )


    </script>


    <center>

        <div class="rightcontent shop_cart border_no">
            <a class="clearcart" href="javascript:" onclick="customButton('确定要清空购物车吗？','确定','shoppingCartHandler.ashx?sid=all','取消');">
                清空购物车</a>
            <h5>
                <span><strong>1.我的购物车</strong></span><span>2.填写购物信息</span><span>3.成功下订</span></h5>
            <table id="tbShoppingCart">
               

            </table>
            <span class="cartbtn">
                <img src="/content/images/shopcar.gif" onclick="javascript:window.location='index.html';"
                    alt="<<继续购物" />
                <img id="imgSettlement" src="/content/images/account.jpg" alt="￥去结算" /></span>
                  <div id="ShoppingCartTotalBind"></div>
       
        </div>
        <!--end rightcontent-->
        <span class="clear"></span>

    </center>
    <div class="clear"></div>

</asp:Content>
